//
//  colors.m
//  justiceRoad
//
//  Created by linzaifei on 2021/1/15.
//  Copyright © 2021 linzaifei. All rights reserved.
//
/**
 #define HexRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]//十六进制转换
 #define HEXRGBA(rgbValue,al) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:al] // 十六进制转换
 */
#import "colors.h"

@implementation colors

NSString *const COLOR_THEME = @"0x78c4d4"; //主题色1

NSString * const COLOR_BG = @"0xf1f1f1";//bg

NSString * const COLOR_BLACK = @"0x000000";//黑色
NSString * const COLOR_DARK = @"0x333333";//深色
NSString * const COLOR_GRAY = @"0x666666";//未浅
NSString * const COLOR_GREY = @"0x999999";//浅色
NSString * const COLOR_WHITE = @"0xffffff";//白色
NSString * const COLOR_LINE = @"0xeeeeee";//分割线


NSString * const COLOR_00 = @"#000000";
NSString * const COLOR_99 = @"#999999";
NSString * const COLOR_21 = @"#212121";
NSString * const COLOR_8E = @"#8E8E8E";
NSString * const COLOR_CC = @"#CCCCCC";
NSString * const COLOR_FF80 = @"#FF804C";
NSString * const COLOR_F6 = @"#F6F6F6";
NSString * const COLOR_51 = @"#515151";
NSString * const COLOR_FFEF = @"#FFEFC2";
NSString * const COLOR_C05E = @"#C05E32";
NSString * const COLOR_FFE5 = @"#FFE589";
NSString * const COLOR_FDD4 = @"#FDD490";
NSString * const COLOR_FFE8 = @"#FFE897";
NSString * const COLOR_78 = @"#787878";
NSString * const COLOR_924B = @"#924B12";
NSString * const COLOR_FFFF00 = @"#FFFF00";
NSString * const COLOR_EA = @"#EAEAEA";
NSString * const COLOR_E980 = @"#E9804C";
NSString * const COLOR_D4B3 = @"#D4B37C";

@end


@implementation UIColor (theme)


+(UIColor *)colorWithLightColor:(UIColor*)lightColor darkColor:(UIColor*)darkColor{
    if (@available(iOS 13.0, *)) {
              return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
                  if([traitCollection userInterfaceStyle] == UIUserInterfaceStyleLight){
                      return lightColor;
                  }else{
                      return darkColor;
                  }
              }];
          }
          return lightColor;
}

+(UIColor *)colorWithHexLightColor:(ColorTypes)lightColor darkColor:(ColorTypes)darkColor{
    return [self colorWithLightColor:HexRGB(lightColor) darkColor:HexRGB(darkColor)];
}

@end

@implementation UIColor(Hex)

+(UIColor *)colorWithHexString:(NSString *)hexColor alpha:(float)opacity{
    NSString * cString = [[hexColor stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];

    // String should be 6 or 8 characters
    if ([cString length] < 6) return [UIColor blackColor];

    // strip 0X if it appears
    if ([cString hasPrefix:@"0X"]) cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"]) cString = [cString substringFromIndex:1];

    if ([cString length] != 6) return [UIColor blackColor];

    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    NSString * rString = [cString substringWithRange:range];

    range.location = 2;
    NSString * gString = [cString substringWithRange:range];

    range.location = 4;
    NSString * bString = [cString substringWithRange:range];

    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];

    return [UIColor colorWithRed:((float)r / 255.0f)
                           green:((float)g / 255.0f)
                            blue:((float)b / 255.0f)
                           alpha:opacity];
}


@end
